package cn.lyf.util;


import cn.lyf.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import javax.servlet.http.HttpSession;

public final class SessionUtils {



    private SessionUtils() {
    }



    public static User getUser() {
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication1 = context.getAuthentication();
        User user = (User) authentication1.getPrincipal();
        return user;
    }

    public static String getUid() {
            User user = getUser();
            if (user == null) {
                return "";
            }
            return user.getId();
    }

    public static String getNickrname() {
        User user = getUser();
        if (user == null) {
            return "";
        }
        return user.getNickname();
    }




}
